package com.zq.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zq.product.dao.dto.CategoryBrandDto;
import com.zq.product.dao.entity.Brand;
import com.zq.product.dao.entity.CategoryBrand;
import com.zq.product.dao.vo.CategoryBrandVO;
import com.zq.product.mapper.CategoryBrandMapper;
import com.zq.product.service.IBrandService;
import com.zq.product.service.ICategoryBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 分类品牌 服务实现类
 * </p>
 *
 * @author 张乔
 * @since 2025-05-13
 */
@Service
@Slf4j
public class CategoryBrandServiceImpl extends ServiceImpl<CategoryBrandMapper, CategoryBrand> implements ICategoryBrandService {



    @Resource
    private CategoryBrandMapper categoryBrandMapper;


    //    查询所有分类品牌
    @Override
    public PageInfo<CategoryBrandVO> findByPage(Integer page, Integer limit,
                                                CategoryBrandDto categoryBrandDto) {


        PageHelper.startPage(page, limit);
        List<CategoryBrandVO> list = categoryBrandMapper.findAll(categoryBrandDto);
        list.forEach(System.err::println);

        log.info("查询所有分类品牌为{}", list);
        PageInfo<CategoryBrandVO> pageInfo = new PageInfo<>(list);
        log.info("查询所有分类品牌分页信息为{}", pageInfo);
        return pageInfo;
    }

@Resource
private IBrandService brandService;

    //    根据分类id查询品牌
    @Override
    public List<Brand> findBrandByCategoryId(Long categoryId) {

        List<CategoryBrand> categoryBrandList = this.list(new LambdaQueryWrapper<CategoryBrand>()
                .eq(CategoryBrand::getCategoryId, categoryId));
        List<Brand> brands = new ArrayList<>();
categoryBrandList.forEach(categoryBrand -> {
    Brand brand = brandService.getById(categoryBrand.getBrandId());
    brands.add(brand);
});
        return brands;
    }


}
